package com.ra.landlord;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.Where;

import com.ra.system.Version;

/**
 * 房屋收费规则
 * 
 * @author Jerry.Feng Date: 2014-07-31
 */
@Entity
@Table(name = "ra_feerulecfg")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
//@Where(clause = "data_status = 1")
public class FeeRuleCfg implements Version, LandlordOwner {

	public final static Integer FEE_RULE_CFG_EXTRA = 0; //额外费用 
	private Integer id;
	
	// 0 - 可用， 1 - 不可用 （注，不同于status的删除与未删除）
	private Integer type;

	private FeeRuleCfgCalc feeRuleCfgCalc;
	
	private FeeRuleCfgDesc feeRuleCfgDesc;
	
	private LandlordOwnerUser landlordUser;
	
	private Integer version;
	
	private Integer status;
	
	@Id
	@GeneratedValue
	@Column(name = "FeeItemId")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "FeeItemtype")
	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	@ManyToOne(targetEntity=FeeRuleCfgCalc.class, cascade=CascadeType.ALL, fetch=FetchType.LAZY)
	@JoinColumn(name = "FeeItemCalcId")
	@Where(clause = "data_status = 1")
	public FeeRuleCfgCalc getFeeRuleCfgCalc() {
		return feeRuleCfgCalc;
	}

	public void setFeeRuleCfgCalc(FeeRuleCfgCalc feeRuleCfgDesc) {
		this.feeRuleCfgCalc = feeRuleCfgDesc;
	}

	@ManyToOne(targetEntity=FeeRuleCfgDesc.class, cascade={CascadeType.MERGE, CascadeType.PERSIST}, fetch=FetchType.LAZY)
	@JoinColumn(name = "FeeItemDescId")
	@Index(name="idx_ra_feerulecfg_FeeItemDescId")
	@Where(clause = "data_status = 1")
	public FeeRuleCfgDesc getFeeRuleCfgDesc() {
		return feeRuleCfgDesc;
	}

	public void setFeeRuleCfgDesc(FeeRuleCfgDesc feeRuleDesc) {
		this.feeRuleCfgDesc = feeRuleDesc;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "createuserid")
	public LandlordOwnerUser getLandlordUser() {
		return landlordUser;
	}

	public void setLandlordUser(LandlordOwnerUser landlordUser) {
		this.landlordUser = landlordUser;
	}

	@Column(name = "version_id")
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	@Column(name = "data_status")
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	
	@Transient
	public String getIdentifyKey()
	{
		return feeRuleCfgDesc.getName() + "#" + feeRuleCfgCalc.getPrice().toString();
	}
}
